package com.example.zkWebClient.common;

public class AjaxCommonResult {
	public static final int SUCCESS_CODE = 1;
	public static final int FAIL_CODE = 0;
	public static final String FAIL_MSG = "失败";
	public static final String SUCCESS_MSG = "成功";

	public int code = FAIL_CODE; // 1表示成功，非1表示错误码
	public String msg; // 错误描述
	public Object data; // 返回的数据

	public AjaxCommonResult() {
	}

	public static AjaxCommonResult success(Object data) {
		return success(data, SUCCESS_MSG);
	}

	public static AjaxCommonResult success(Object data, String msg) {
		AjaxCommonResult result = new AjaxCommonResult();
		result.data = data;
		result.msg = msg == null ? SUCCESS_MSG : msg;
		result.code = SUCCESS_CODE;
		return result;
	}

	public static AjaxCommonResult fail() {
		return fail(FAIL_CODE, FAIL_MSG);
	}

	public static AjaxCommonResult fail(int code) {
		return fail(code, FAIL_MSG);
	}

	public static AjaxCommonResult fail(int code, String msg) {
		AjaxCommonResult result = new AjaxCommonResult();
		result.msg = msg == null ? FAIL_MSG : msg;
		result.code = code == SUCCESS_CODE ? FAIL_CODE : code;
		return result;
	}

}
